/*
* jiyan1
*/
package com.jiyan.errorcode.ctrl;


import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

import com.jiyan.core.exceptions.BaseException;
import com.jiyan.core.entity.BeanRet;
import com.jiyan.core.entity.Page;
import com.jiyan.core.tools.redis.RedisUtils;
import com.jiyan.errorcode.entity.ErrorcodePool;
import com.jiyan.errorcode.service.ErrorcodePoolSVImpl;

/**
 * 错误码库 控制器
 *
 * @author jiyan
 */
@RestController
@RequestMapping("/errorcodePool")
@Slf4j
@Api(value = "错误码库控制器", description = "错误码库控制器")
public class ErrorcodePoolCtrl {

    @Resource
    protected RedisUtils redisUtils;
    @Autowired
    private ErrorcodePoolSVImpl errorcodePoolSVImpl;


    /**
    * 查询ErrorcodePool一个详情信息
    * @param id 
    * @param errorCode 错误码 由人为定义并制定出来指定一定场景模块的错误编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id,java.lang.String errorCode) {
        if(id==null){
          return null;
        }
        if(errorCode==null){
          return null;
        }
        ErrorcodePool errorcodePool = errorcodePoolSVImpl.load(id,errorCode);
        log.info(JSON.toJSONString(errorcodePool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errorcodePool);
    }


    /**
    * 根据条件id查询ErrorcodePool一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if(id==null||id==0){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrorcodePool errorcodePool = errorcodePoolSVImpl.loadById(id);
        log.info(JSON.toJSONString(errorcodePool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errorcodePool);
    }
    /**
    * 根据条件errorCode查询ErrorcodePool一个详情信息
    *
    * @param errorCode 错误码 由人为定义并制定出来指定一定场景模块的错误编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/errorCode/{errorCode}")
    @ResponseBody
    public BeanRet loadByErrorCode(@PathVariable java.lang.String errorCode) {
        if(StringUtils.isEmpty(errorCode)){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrorcodePool errorcodePool = errorcodePoolSVImpl.loadByErrorCode(errorCode);
        log.info(JSON.toJSONString(errorcodePool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errorcodePool);
    }


    /**
    * 查询ErrorcodePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询ErrorcodePool信息集合", notes = "查询ErrorcodePool信息集合")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),

    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore ErrorcodePool errorcodePool,@ApiIgnore Page<ErrorcodePool> page) {
        if(page==null){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<ErrorcodePool> errorcodePools = errorcodePoolSVImpl.list(errorcodePool,page.getCurPage(),page.getPageSize());
        int total = errorcodePoolSVImpl.count(errorcodePool);
        page.setTotalRow(total);
        page.setVoList(errorcodePools);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }


    /**
    * 查询ErrorcodePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询ErrorcodePool信息集合", notes = "查询ErrorcodePool信息集合")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id,java.lang.String errorCode,@ApiIgnore Page<ErrorcodePool> page) {
        if(page==null){
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<ErrorcodePool> errorcodePools = errorcodePoolSVImpl.list(id,errorCode, page.getCurPage(),page.getPageSize());
        int total = errorcodePoolSVImpl.count(id,errorCode);
        page.setTotalRow(total);
        page.setVoList(errorcodePools);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
    * 创建ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建ErrorcodePool", notes = "创建ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query"),
        @ApiImplicitParam(name = "sceneCode", value = "场景编码", paramType = "query"),
        @ApiImplicitParam(name = "info", value = "文本对照,默认的错误信息提示", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "错误码说明解释错误码的作用和表达意思", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore ErrorcodePool errorcodePool) {
        if (StringUtils.isEmpty(errorcodePool.getErrorCode())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getSceneCode())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getInfo())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getSummary())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        errorcodePoolSVImpl.save(errorcodePool);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success,errorcodePool);
    }


    /**
    * 修改ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改ErrorcodePool", notes = "修改ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query"),
        @ApiImplicitParam(name = "sceneCode", value = "场景编码", paramType = "query"),
        @ApiImplicitParam(name = "info", value = "文本对照,默认的错误信息提示", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "错误码说明解释错误码的作用和表达意思", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore ErrorcodePool errorcodePool) {
        if (StringUtils.isEmpty(errorcodePool.getErrorCode())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getSceneCode())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getInfo())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errorcodePool.getSummary())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        errorcodePoolSVImpl.modify(errorcodePool);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success,errorcodePool);
    }

    /**
    * 根据主键删除ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除ErrorcodePool", notes = "删除ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String errorCode) {
        if (id!=null&&StringUtils.isEmpty(errorCode)) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }

        errorcodePoolSVImpl.delete(id,errorCode);
        return BeanRet.create(true, "删除ErrorcodePool成功");
    }


}
